﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;

namespace SAM_Edu.dao
{
   public class daoAccessRights
    {
      

      



        private static String errMsg;
        public static DataSet loadUsername()
        {
            MySqlConnection conn = DatabaseConnection.getConnection();

            MySqlDataAdapter da;
            DataSet usernames = new DataSet();

            string cmd = "SELECT * FROM Accounts";

            try
            {
                conn.Open();
                da = new MySqlDataAdapter(cmd, conn);
                da.Fill(usernames);
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }
            finally
            {
                conn.Close();
            }
            return usernames;
        }

      

        public static DataSet loadUsername(string search)
        {
            MySqlConnection conn = DatabaseConnection.getConnection();

            MySqlDataAdapter da;
            DataSet accinfo = new DataSet();

            string cmd = "SELECT * FROM Accounts WHERE username LIKE '%" + search + "%'";

            try
            {
                conn.Open();
                da = new MySqlDataAdapter(cmd, conn);
                da.Fill(accinfo);
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }
            finally
            {
                conn.Close();
            }
            return accinfo;
        }
        public static DataSet loadUID(int search)
        {
            MySqlConnection conn = DatabaseConnection.getConnection();

            MySqlDataAdapter da;
            DataSet userinfo = new DataSet();

            string cmd = "SELECT * FROM user WHERE userid = '" + search + "'";

            try
            {
                conn.Open();
                da = new MySqlDataAdapter(cmd, conn);
                da.Fill(userinfo);
            }
            catch (Exception ex)
            {
                errMsg = ex.Message;
            }
            finally
            {
                conn.Close();
            }
            return userinfo;
        }
    }
}
